package com.ruoyi.common.utils.sso;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

public class AjaxJson extends LinkedHashMap<String, Object> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final int CODE_SUCCESS = 200;			// 成功状态码
    public static final int CODE_ERROR = 500;			// 错误状态码
    public static final int CODE_WARNING = 501;			// 警告状态码
    public static final int CODE_NOT_JUR = 403;			// 无权限状态码
    public static final int CODE_NOT_LOGIN = 401;		// 未登录状态码
    public static final int CODE_INVALID_REQUEST = 400;	// 无效请求状态码


    /** 返回code */
    public Integer getCode() {
        return (Integer)this.get("code");
    }

    public AjaxJson setCode(int code) {
        this.put("code", code);
        return this;
    }

    /** 获取data */
    public Object getData() {
        return this.get("data");
    }

    public AjaxJson setData(Object data) {
        this.put("data", data);
        return this;
    }

    /** 获取msg */
    public String getMsg() {
        return (String)this.get("msg");
    }

    public AjaxJson setMsg(String msg) {
        this.put("msg", msg);
        return this;
    }


    /** 返回成功 */
    public static AjaxJson getSuccess() {
        return new AjaxJson(CODE_SUCCESS, "ok", null);
    }


    public AjaxJson(int code, String msg, Object data) {
        this.setCode(code);
        this.setMsg(msg);
        this.setData(data);
    }

    public AjaxJson(Map<String, Object> map) {
        for (String key: map.keySet()) {
            this.set(key, map.get(key));
        }
    }

    public AjaxJson set(String key, Object data) {
        this.put(key, data);
        return this;
    }

}
